/**
 * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see https://ckeditor.com/legal/ckeditor-oss-license
 */

//  移动支票
if(typeof(g6_is_mobile) == "undefined") g6_is_mobile = false;


CKEDITOR.editorConfig = function( config ) {
	// 设置设计器的高度
	if(typeof(editor_height) != "undefined") {
		config.height = editor_height+"px";
	}

	// 语言设置
	config.language = 'ko';
	// 字体相关
	config.font_names = '清除哥特式;横滚;古利姆索;宫殿;射箭;发芽;放大身体;接地;巴尔唐;';  // + CKEDITOR.config.font_names;
	config.font_defaultLabel = '清除哥特式';
	//config.font_defaultLabel = 'Malgun Gothic';
	// 字母大小输出
	config.fontSize_sizes = '8pt;9pt;10pt;11pt;12pt;14pt;16pt;20pt;24pt;30pt;48pt;60pt;72pt;';

	// 工具栏功能按钮顺序
	config.toolbarGroups = [
		{ name: '1', groups: [ 'styles', 'align', 'basicstyles', 'cleanup' ] },
		{ name: '2', groups: [ 'insertImg', 'insert', 'colors', 'list', 'blocks', 'links', 'mode', 'tools', 'about' ] }
	];

	// 未曝光功能按钮
	if(g6_is_mobile) {
		//--- 移动电话 ---//
		config.removeButtons = 'Print,Cut,Copy,Paste,Subscript,Superscript,Anchor,Unlink,ShowBlocks,Undo,Redo,Smiley,Font,Italic,Underline,Strike,BGColor';

        config.toolbarGroups = [
            { name: '1', groups: [ 'styles', 'align', 'basicstyles', 'insertImg', 'colors', 'links', 'mode' ] }
        ];
	} else {
		//--- PC ---//
		config.removeButtons = 'Print,Cut,Copy,Paste,Subscript,Superscript,Anchor,Unlink,ShowBlocks,Undo,Redo,Smiley';
	}

	/* 图片上传相关来源 */
	let up_url = g6_url + "editor/ckeditor4/upload?type=Images";

	// 设计师的分工
	if(typeof(editor_id) != "undefined" && editor_id != "") {
		up_url += "&editor_id="+editor_id;
	}
	// 上传路径 - editor_uri
	if(typeof(editor_uri) != "undefined" && editor_uri != "") {
		up_url += "&editor_uri="+editor_uri;
	}
	// Tokes上传图片
	if( typeof(editor_form_name) != "undefined" && editor_form_name != "") {
		up_url += "&editor_form_name="+editor_form_name;
	}
    
	// 上传页面 URL 声明
	config.filebrowserImageUploadUrl = up_url;

	// 图像拨盘校正 
	CKEDITOR.on('dialogDefinition', function (ev) {
		let dialogName = ev.data.name;
		let dialog = ev.data.definition.dialog;
		let dialogDefinition = ev.data.definition;
		if (dialogName == 'image') {
			dialog.on('show', function (obj) {
				//this.selectPage('Upload'); //从上传tep开始
			});
			dialogDefinition.removeContents('advanced'); // 详细删除选项卡
			dialogDefinition.removeContents('Link'); // “删除链接” 选项卡
			
			var infoTab = dialogDefinition.getContents('info');   
			infoTab.remove('txtHSpace');
			infoTab.remove('txtVSpace');
			infoTab.remove('htmlPreview');	// 删除视图
		}
	});

	// 添加要使用的插件
    let ck_extraPlugins = 'uploadwidget,uploadimage,editorplaceholder';

    config.extraPlugins = ck_extraPlugins;

	// 调用文本内容时的Maint属性
	config.allowedContent = true;

	// iOS仅适用
	if(/iPhone|iPad|iPod/i.test(navigator.userAgent) ) {
		// 在与韩语输入和应用相关的线切割过程中出现问题
		config.removePlugins = 'enterkey';
	}

	if (localStorage.getItem('color-theme') == 'dark') {
		config.contentsCss = [CKEDITOR.getUrl('darkmode.css')];
    }
};

